#pragma once
#include <iostream>
using namespace std;
void Usage(const char* first)
{
    cout << "ScanfError" << endl;
    cout << "Usage:" << first << " + num(num > 0)" << endl;
}

bool CheckStdin(int argc, const char* argv[])
{
    if(argc != 2 || argv[1] <= 0)
    {
        Usage(argv[0]);
        return false;
    }
    return true;
}


typedef void(* task) ();

void PrintLog()
{
    cout << "printf log task" << endl;
}

void ReloadConf()
{
    cout << "reload conf task" << endl;
}

void ConnectMysql()
{
    cout << "connect mysql task" << endl;
}

task Task[3] = {PrintLog, ReloadConf, ConnectMysql};

int GetNextTask()
{
    return rand() % 3;
}


void work()
{
    while(true)
    {
        uint32_t task_node = 0;
        ssize_t n = read(0, &task_node, sizeof(task_node));
        //读到末尾了，子进程不需要执行任务，退出
        if(n == 0)
        {
            break;
        }
        else if(n == sizeof(task_node))
        {
            Task[task_node]();
        }
        // cout << "I am worker: " << getpid() << endl;
        // cout << endl;
        sleep(1);
    }

}